﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Twodi.Implemented
{
    /// <summary>
    /// Pedaço da Animação.
    /// </summary>
    public class AnimationFrame
    {
        /// <summary>
        /// Construtor do frame.
        /// </summary>
        /// <param name="x">Ponto X do retangulo.</param>
        /// <param name="y">Ponto Y do retangulo.</param>
        /// <param name="widht">Largura do retangulo</param>
        /// <param name="height">Altura do retangulo</param>
        public AnimationFrame(int x, int y, int widht, int height)
            : this(new Rectangle(x, y, widht, height))
        {

        }

        /// <summary>
        /// Construtor do frame.
        /// </summary>
        /// <param name="x">Ponto X do retangulo.</param>
        /// <param name="y">Ponto Y do retangulo.</param>
        /// <param name="widht">Largura do retangulo</param>
        /// <param name="height">Altura do retangulo</param>
        /// <param name="duration">Duração do frame.</param>
        public AnimationFrame(int x, int y, int widht, int height, TimeSpan duration)
            : this(new Rectangle(x, y, widht, height), duration)
        {

        }

        /// <summary>
        /// Construtor do frame.
        /// </summary>
        /// <param name="source">Retangulo que será usado como source.</param>
        public AnimationFrame(Rectangle source)
            : this(TimeSpan.FromSeconds(1))
        {
            Source = source;
        }

        /// <summary>
        /// Construtor do frame.
        /// </summary>
        /// <param name="source">Retangulo que será usado como source.</param>
        /// <param name="duration">Duração do frame.</param>
        public AnimationFrame(Rectangle source, TimeSpan duration)
            : this(duration)
        {
            Source = source;
        }

        /// <summary>
        /// Construtor do frame.
        /// </summary>
        /// <param name="duration">Duração do frame.</param>
        protected AnimationFrame(TimeSpan duration)
        {
            Duration = duration;
        }

        /// <summary>
        /// Duração do Frame.
        /// </summary>
        #region Attribute Duration

        /// <summary>
        /// Duração do Frame.
        /// </summary>
        private TimeSpan duration;

        /// <summary>
        /// Property: Duração do Frame.
        /// </summary>
        public TimeSpan Duration
        {
            get { return this.duration; }
            set
            {
                this.duration = value;
                onDurationChanged(EventArgs.Empty);
            }
        }

        /// <summary>
        /// Evento invocado quando valor de "Duration" é alterado(a).
        /// </summary>
        public event EventHandler<EventArgs> DurationChanged;

        /// <summary>
        /// Método responsavel por invocar o evento DurationChanged;
        /// </summary>
        protected virtual void onDurationChanged(EventArgs e)
        {
            if (DurationChanged != null)
            {
                DurationChanged(this, e);
            }
        }

        #endregion Attribute Duration

        /// <summary>
        /// Região do Sprite.
        /// </summary>
        #region Attribute Source

        /// <summary>
        /// Região do Sprite.
        /// </summary>
        private Rectangle source;

        /// <summary>
        /// Property: Região do Sprite.
        /// </summary>
        public Rectangle Source
        {
            get { return this.source; }
            set
            {
                this.source = value;
                onSourceChanged(EventArgs.Empty);
            }
        }

        /// <summary>
        /// Evento invocado quando valor de "Source" é alterado(a).
        /// </summary>
        public event EventHandler<EventArgs> SourceChanged;

        /// <summary>
        /// Método responsavel por invocar o evento SourceChanged;
        /// </summary>
        protected virtual void onSourceChanged(EventArgs e)
        {
            if (SourceChanged != null)
            {
                SourceChanged(this, e);
            }
        }

        #endregion Attribute Source
    }
}
